package com.egao.orderB.controller2;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.Customer;
import com.egao.orderB.service.CustomerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 货代管理
 * @author : Doman
 * @date : 2020-06-02 13:34:13
 * @version ：1.0
 */

//@Api(tags = "货代管理")
//@RestController
//@RequestMapping("/api/customer2")
public class CustomerController extends BaseController {

	@Autowired
	private CustomerService customerService;

	/**
	 * 分页查询列表
	 */
    @PreAuthorize("hasAuthority('orderB:customer:list')")
	@OperLog(value = "货代管理", desc = "分页查询")
    @ApiOperation("分页查询货代管理")
    @ApiPageParam
	@PostMapping("/page")
    public JsonResult list(PageResult2<T> page, Customer customer) throws Exception{
        return customerService.list(page, customer, getLoginUser());
    }

    /**
     * 查询全部货代管理
     */
    @PreAuthorize("hasAuthority('orderB:customer:list')")
    @OperLog(value = "货代管理", desc = "查询全部")
    @ApiOperation("查询全部货代管理")

    @PostMapping("/list")
    public JsonResult list(Customer customer){
        return customerService.list(customer, getLoginUser());
    }

    /**
     * 根据id查询货代管理
     */
    @PreAuthorize("hasAuthority('orderB:customer:list')")
    @OperLog(value = "货代管理", desc = "根据id查询")
    @ApiOperation("根据id查询货代管理")

    @PostMapping("/get")
    public JsonResult get(Customer customer) {
        return JsonResult.ok().setData(customerService.getById(customer));
		// 使用关联查询
        //PageParam<customer> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<customer> records = customerService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加货代管理
     */
    @PreAuthorize("hasAuthority('orderB:customer:save')")
    @OperLog(value = "货代管理", desc = "添加", param = false, result = true)
    @ApiOperation("添加货代管理")

    @PostMapping("/save")
    public JsonResult save(Model model, Customer customer) {
        return customerService.save(customer, getLoginUser());
    }

    /**
     * 修改货代管理
     */
    @PreAuthorize("hasAuthority('orderB:customer:update')")
    @OperLog(value = "货代管理", desc = "修改", param = false, result = true)
    @ApiOperation("修改货代管理")

    @PostMapping("/update")
    public JsonResult update(Model model, Customer customer) {
        return customerService.update(customer, getLoginUser());
    }

    /**
     * 删除货代管理
     */
    @PreAuthorize("hasAuthority('orderB:customer:remove')")
    @OperLog(value = "货代管理", desc = "删除", result = true)
    @ApiOperation("删除货代管理")

    @PostMapping("/remove")
    public JsonResult remove(Customer customer ) {
        return customerService.remove(customer, getLoginUser());
    }

    /**
     * 批量添加货代管理
     */
    /**@RequiresPermissions("orderB:customer:save")
    @OperLog(value = "货代管理", desc = "批量添加", param = false, result = true)

    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Customer> list) {
        if (customerService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改货代管理
     */
    /**@RequiresPermissions("orderB:customer:update")
    @OperLog(value = "货代管理", desc = "批量修改", result = true)

    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Customer> batchParam) {
        if (batchParam.update(customerService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除货代管理
     */
    /**@RequiresPermissions("orderB:customer:remove")
    @OperLog(value = "货代管理", desc = "批量删除", result = true)

    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (customerService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
